<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    textarea {
      width: 300px;
      height: 200px;
    }
  </style>
</head>

<body>
  <div id="app">
    <textarea name="" id="" v-model="count" @input="much"></textarea>
    <span v-if="count.length <= total">剩余字数:{{rest}}/{{total}}</span>
  </div>
</body>
<script src="./vue.js"></script>
<script>
  let { createApp, ref} = Vue;
  createApp({
    setup() {
      let count = ref('');
      let total = 200;
      let rest = ref(total - count.value.length);
      function much() {
        count.value = count.value.slice(0, total);
        rest.value = total - count.value.length;
      };
      return {
        count,
        rest,
        much,
        total
      };
    }
  }).mount("#app");
</script>

</html>